#导入Library类
from django.template import Library

from app.models import Subtitle,SubtitleImage,SubtitleVideo,TopicType
#创建一个Library类对象
register=Library()

#使用装饰器进行注册
@register.filter
#定义求余函数mod，将value对2求余
def mod(value):
    return value%2 == 0


@register.filter
def subtitle(topic):
    subtitles = Subtitle.objects.filter(topic=topic).order_by('index')
    return subtitles

@register.filter
def subtitle_show(topic):
    subtitle_shows = Subtitle.objects.filter(topic=topic).exclude(desc='').order_by('index')
    return subtitle_shows

@register.filter
def subtitle_image(subtitle):
    subtitle_images = SubtitleImage.objects.filter(subtitle=subtitle).order_by('index')
    return subtitle_images

@register.filter
def subtitle_video(subtitle):
    subtitle_videos = SubtitleVideo.objects.filter(subtitle=subtitle).order_by('index')
    return subtitle_videos